package model.persistencia.dao;

import java.util.HashMap;
import java.util.List;

import model.bean.Matricula;
import model.bean.Turma;

public class MatriculaDAO extends GenericDAO<Matricula> {

	public MatriculaDAO(Class persistentClass) {
		super(persistentClass);
	}
	
	public MatriculaDAO(){
		this(Matricula.class);
	}
	
	public List<Matricula> listarAlunosIndicados(StringBuilder hqlCondicao, HashMap<String, Object> parametros) {
		
		StringBuilder hql = new StringBuilder();
		
		hql.append("select matricula from "+Matricula.class.getName()+ " matricula ");
		hql.append(" inner join matricula.aluno aluno ");
		hql.append(" inner join matricula.indicacao indicacao ");
		hql.append(" where 1 = 1 ");
		
		hql.append(hqlCondicao.toString());
	      
		return listar(hql.toString(), parametros);
		
	}
	

	public List<Matricula> getAlunosComIndicacao(Turma turma){
		String query = "SELECT m FROM "+Matricula.class.getName()+" AS m " +
				"INNER JOIN m.aluno  AS a INNER JOIN m.turma AS t " +
				"INNER JOIN m.indicacao as i " +
				"WHERE t.id = :turma";
		HashMap parametros = new HashMap();
		parametros.put("turma", turma.getId());
		
		return listar(query, parametros);
	}
	
	public List<Matricula> getAlunosSemIndicacao(Turma turma){
		String query = "SELECT m FROM "+Matricula.class.getName()+" AS m " +
				"INNER JOIN m.aluno  AS a INNER JOIN m.turma AS t " +
				"LEFT JOIN m.indicacao as i " +
				"WHERE t.id = :turma AND i.id is null";
		HashMap parametros = new HashMap();
		parametros.put("turma", turma.getId());
		
		return listar(query, parametros);
	}
}
